home *** CD-ROM | disk | FTP | other *** search
-
- package sub_arctic.lib;
-
- import sub_arctic.output.loaded_image;
- import sub_arctic.output.drawable;
- import sub_arctic.input.pressable;
- import sub_arctic.input.snap_draggable;
- import sub_arctic.input.snap_targetable;
- import sub_arctic.input.event;
- import sub_arctic.input.user_info_holder;
- import sub_arctic.lib.manager;
-
- import java.awt.Point;
-
- /**
- * This is a subclass of drag_container which does snapping behavior.
- * Snapping is controlled by a set of feature points within a dragged object.
- * This container advertises all the feature points of all its children as its
- * own. See the snap-drag agent for full details on how snapping works.
- *
- * @see sub_arctic.input.snap_drag_agent
- * @see sub_arctic.input.snap_draggable
- * @see sub_arctic.input.snap_targetable
- * @author Scott Hudson
- */
- public class snap_container extends drag_container implements snap_draggable {
-
- /**
- * Full constructor.
- *
- * @param int x initial x position of the container.
- * @param int y initial y position of the container.
- * @param boolean do_bb_feedback do we do bounding box drag feedback.
- */
- public snap_container(int x, int y, boolean do_bb_feedback)
- {
- super(x,y,do_bb_feedback);
- }
-
- //had:
- //* @exception general PROPAGATED.
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Handle mouse button press input to the object. Here, we start dragging.
- *
- * @param event evt the press event.
- * @param Object user_info the information associated with this object at
- * pick time.
- * @return boolean indicating whether we have consumed this event.
- */
- public boolean press(event evt, Object user_info)
- {
- manager.snap_drag_focus.set_focus_to(this, evt, new point_info(0,0));
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- /* Report our feature points on the basis of our children's points */
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Report number of feature points as sum of visible children's feature
- * points.
- * @return int number of feature points we advertise.
- */
- public int num_feature_points()
- {
- interactor ch;
- int total = 0;
-
- for (int i = 0; i < num_children(); i++)
- {
- ch = child(i);
- if (ch != null && ch.visible()) total += ch.num_feature_points();
- }
-
- return total;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Report a feature point out of our children. Our feature point indexes
- * are based on placing the first child's indexes after the zeroth, etc.
- *
- * @param int indx the feature point being asked for.
- * @return Point the feature point requested or 0,0 if index is out of range.
- */
- public Point feature_point(int indx)
- {
- int start_of_ch, start_of_next, i;
- interactor ch;
-
- /* handle index out of range with a default */
- if (indx < 0) return new Point(0,0);
-
- /* find the child that has our index */
- start_of_ch = 0;
- for (i = 0; i < num_children(); i++)
- {
- /* get the child, but process only if its visible */
- ch = child(i);
- if (!ch.visible()) continue;
-
- start_of_next = start_of_ch + ch.num_feature_points();
-
- /* is this the child? */
- if (indx >= start_of_ch && indx < start_of_next)
- {
- /* return the feature point transformed into our coords */
- return ch.into_parent(ch.feature_point(indx - start_of_ch));
- }
-
- /* move to the next child */
- start_of_ch = start_of_next;
- }
-
- /* if we get here we have an index out of range and we do the default */
- return new Point(0,0);
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Report a feature point enable status out of our children. Our feature
- * point indexes are based on placing the first child's indexes after the
- * zeroth, etc.
- *
- * @param int indx the index of the feature point we are enquiring about.
- * @return boolean indicating whether that feature point is enabled (we will
- * always return false of index out of bounds).
- */
- public boolean feature_point_enabled(int indx)
- {
- int start_of_ch, start_of_next, i;
- interactor ch;
-
- /* handle index out of range with a default */
- if (indx < 0) return false;
-
- /* find the child that has our index */
- start_of_ch = 0;
- for (i = 0; i < num_children(); i++)
- {
- /* get the child, but process only if its visible */
- ch = child(i);
- if (!ch.visible()) continue;
-
- start_of_next = start_of_ch + ch.num_feature_points();
-
- /* is this the child? */
- if (indx >= start_of_ch && indx < start_of_next)
- {
- /* return the feature point at offset index */
- return ch.feature_point_enabled(indx - start_of_ch);
- }
-
- /* move to the next child */
- start_of_ch = start_of_next;
- }
-
- /* if we get here we have an index out of range and we do the default */
- return false;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- /* Snap_draggable methods */
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate that the object should snap to a given target object. Here
- * we move the object to the snap point.
- *
- * @param event evt the event "causing" the snap.
- * @param Point orig_pt where this object would be without
- * the snap.
- * @param Point snap_pt where this object is with the snap.
- * @param int feature_pt_indx the feature point of this object
- * that we are snapping with.
- * @param snap_targetable target_obj the target object we are snapping
- * to.
- * @param Object user_info the user info for this input.
- * @return boolean indicating if the input has been consumed.
- */
- public boolean snap_to(
- event evt,
- Point orig_pt,
- Point snap_pt,
- int feature_pt_indx,
- snap_targetable target_obj,
- Object user_info)
- {
- set_pos(snap_pt);
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Perform feedback while a snap is active. Here we do nothing.
- *
- * @param event evt the event "causing" the snap.
- * @param Point orig_pt where this object would be without
- * the snap.
- * @param Point snap_pt where this object is with the snap.
- * @param int feature_pt_indx the feature point of this object
- * that we are snapping with.
- * @param snap_targetable target_obj the target object we are snapping
- * to.
- * @param Object user_info the user info for this input.
- * @return boolean indicating if the input has been consumed.
- */
- public boolean snap_feedback(
- event evt,
- Point orig_pt,
- Point snap_pt,
- int feature_pt_indx,
- snap_targetable target_obj,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate that the object is no longer snapped to a given target object.
- * Here we return the object to its nominal position.
- *
- * @param event evt the event "causing" the unsnap.
- * @param Point orig_pt where this object should be without
- * the snap.
- * @param Point snap_pt where this object was with the snap.
- * @param int feature_pt_indx the feature point of this object
- * that we were snapping with.
- * @param snap_targetable target_obj the target object we were snapping
- * to.
- * @param Object user_info the user info for this input.
- * @return boolean indicating if the input has been consumed.
- */
- public boolean unsnap_to(
- event evt,
- Point orig_pt,
- Point snap_pt,
- int feature_pt_indx,
- snap_targetable target_obj,
- Object user_info)
- {
- set_pos(orig_pt);
-
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate that the object should anti-snap to a given target object.
- * Here we just move the object to the anti-snap position.
- *
- * @param event evt the event "causing" the anti-snap.
- * @param Point orig_pt where this object would be without
- * the anti-snap.
- * @param Point snap_pt where this object is with the
- * anti-snap.
- * @param int feature_pt_indx the feature point of this object
- * that we are anti-snapping with.
- * @param snap_targetable target_obj the target object we are
- * anti-snapping to.
- * @param Object user_info the user info for this input.
- * @return boolean indicating if the input has been consumed.
- */
- public boolean anti_snap_to(
- event evt,
- Point orig_pt,
- Point snap_pt,
- int feature_pt_indx,
- snap_targetable target_obj,
- Object anti_snap_info,
- Object user_info)
- {
- set_pos(orig_pt);
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Perform feedback while an anti-snap is active. Here we do nothing.
- *
- * @param event evt the event "causing" the anti-snap.
- * @param Point orig_pt where this object would be without
- * the anti-snap.
- * @param Point snap_pt where this object is with the
- * anti-snap.
- * @param int feature_pt_indx the feature point of this object
- * that we are anti-snapping with.
- * @param snap_targetable target_obj the target object we are
- * anti-snapping to.
- * @param Object user_info the user info for this input.
- * @return boolean indicating if the input has been consumed.
- */
- public boolean anti_snap_feedback(
- event evt,
- Point orig_pt,
- Point snap_pt,
- int feature_pt_indx,
- snap_targetable target_obj,
- Object anti_snap_info,
- Object user_info)
- {
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
-
- /**
- * Indicate that the object is no longer anti-snapped to a given target
- * object. Here we just move back to our nominal position.
- *
- * @param event evt the event "causing" the unanti-snap.
- * @param Point orig_pt where this object should be without
- * the anti-snap.
- * @param Point snap_pt where this object was with the
- * anti-snap.
- * @param int feature_pt_indx the feature point of this object
- * that we were anti-snapping with.
- * @param snap_targetable target_obj the target object we were
- * anti-snapping to.
- * @param Object user_info the user info for this input.
- * @return boolean indicating if the input has been consumed.
- */
- public boolean unanti_snap_to(
- event evt,
- Point orig_pt,
- Point snap_pt,
- int feature_pt_indx,
- snap_targetable target_obj,
- Object anti_snap_info,
- Object user_info)
- {
- set_pos(orig_pt);
- return true;
- }
-
- /* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . */
- }
- /*=========================== COPYRIGHT NOTICE ===========================
-
- This file is part of the subArctic user interface toolkit.
-
- Copyright (c) 1996 Scott Hudson and Ian Smith
- All rights reserved.
-
- The subArctic system is freely available for most uses under the terms
- and conditions described in
- http://www.cc.gatech.edu/gvu/ui/sub_arctic/sub_arctic/doc/usage.html
- and appearing in full in the lib/interactor.java source file.
-
- The current release and additional information about this software can be
- found starting at: http://www.cc.gatech.edu/gvu/ui/sub_arctic/
-
- ========================================================================*/
-